home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / concol10.zip / CONCOL.C next >
C/C++ Source or Header  |  1992-11-29  |  2KB  |  63 lines

  1. /*******
  2.  
  3.   Description: console color program
  4.   Title: CONCOL
  5.   Rev.:  Date:     Features:
  6.          92-09-16     Showing the possible colors on the console
  7.   v1.0:  92-10-07  Setting the console colors via commandline
  8.  
  9. *******/
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include <windows.h>
  16.  
  17. HANDLE     hConsole;
  18.  
  19. main(int argc, char *argv[])
  20. {
  21. WORD i, j;
  22. CONSOLE_SCREEN_BUFFER_INFO csbi;    /* console screen buffer info    */
  23.  
  24.   /* get/create output handle */
  25.   hConsole = CreateFile("CONOUT$", 
  26.   GENERIC_WRITE | GENERIC_READ,
  27.   FILE_SHARE_READ | FILE_SHARE_WRITE,
  28.         0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
  29.         0L);
  30.   if(hConsole== INVALID_HANDLE_VALUE) {
  31.     printf("\nError: %s is unable to open output console.\n", argv[0]);
  32.     return( 0 );
  33.   }
  34.   /* checking for commandline parameter */
  35.   if (argc==2) {  
  36.       /* one parameter passed on commandline */
  37.     SetConsoleTextAttribute(hConsole, (WORD)atoi(argv[1])); 
  38.   } else {
  39.       /* no commandline parameter: Show title, syntax, possible colors */
  40.     printf("\nSet Console Color\t\tVersion 1.00 (Oct) by O.Dippel\n");
  41.     /* Get current Color-Attributes */
  42.     GetConsoleScreenBufferInfo(hConsole, &csbi);
  43.     /* no parameter passed: Syntax - info , Show all color combinations */
  44.     SetConsoleTextAttribute(hConsole, 30);
  45.     printf("Usage: %s [<console color>]\n", argv[0]);
  46.     printf("choose one of the following numbers as <console color>\n");
  47.     SetConsoleTextAttribute(hConsole, csbi.wAttributes);
  48.     printf("\n");
  49.     for(i=0;i<16;i++) {
  50.       for(j=0;j<16;j++) {
  51.         SetConsoleTextAttribute(hConsole, (WORD)(i<<4 | j));
  52.         printf("%4d", i*16 + j);
  53.       }
  54.       /* set stored color for CR/LF */
  55.       SetConsoleTextAttribute(hConsole, csbi.wAttributes);
  56.       printf("\n");
  57.     }
  58.     SetConsoleTextAttribute(hConsole, csbi.wAttributes);
  59.   }
  60.   /* everyting is ok - Goodbye */    
  61.   return(0);
  62. }
  63.